public class Test {
    //测试开箱与装箱
    public static void main(String[] args){
        Integer a = 100;
        Integer b = 100;
        System.out.println(a == b);
        Integer c = 200;
        Integer d = 200;
        System.out.println(c == d);
    }
}

//泛型练习
//新建了一个Love类，里面有两个方法
class Love<T>{
//    public T[] obj = (T[]) new Object[3];
    public Object[] obj = new Object[3];
    public void setPos(int pos,T val){
        obj[pos] = val;
    }
    public T getPos(int pos){
        return (T) obj[pos];
    }
}

class Test1{
    public static void main(String[] args){
        Love<String> myArray = new Love<String>();
        myArray.setPos(0,"宽恕");
        myArray.setPos(1,"理解");
        myArray.setPos(2,"克制");
        String a = myArray.getPos(0);
        Object a1 = myArray.getPos(1);
        System.out.println(a);
        System.out.println(a1);
    }
}
//新建一个使用泛型的“盘子”类
class Plate<T>{
    T[] BigPlate = (T[]) new Object[3];//有三个容量单位的大盘子
    public void putFood(int pos,T val){
        BigPlate[pos] = val;
    }
    public T getFood(int pos){
        return BigPlate[pos];
    }
}
class Test2{
    public static void main(String[] args) {
        Plate<Integer> plate = new Plate<Integer>();//测试：“T”是否可以替换为其他引用类型？？？
        plate.putFood(0,1);
        plate.putFood(1,2);
        plate.putFood(2,3);
        int a = plate.getFood(2);
        System.out.println(a);
    }
    public static void main1(String[] args) {
        Plate<String> plate = new Plate<String>();//创建了一个“盘子”对象，里面有一个BigPlate数组
        plate.putFood(0,"蒸熊掌");
        plate.putFood(1,"蒸鹿眼");
        plate.putFood(2,"烧花鸭");
        String a = plate.getFood(2);
        System.out.println(a);
    }
}
class Alg2{//泛型方法
    public <E extends Comparable<E>> E findMax(E[] array){//泛型方法
        E max = array[0];
        for (int i = 1;i < array.length;i++){
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}
class Test3{
    public static void main(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] array = {1,2,3,4,5,6,7};
        Integer val = alg2.<Integer>findMax(array);
        System.out.println(val);
    }
}
class Alg3 <E extends Comparable<E>>{//泛型上界
    public E findMax3(E[] array){
        E max = array[0];
        for (int i = 1;i < array.length;i++){
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}
class Test4{
    public static void main(String[] args) {
        Alg3<Integer> alg3 = new Alg3();
        Integer[] array = {1,2,3,4,5,6,7};
        Integer val = alg3.<Integer>findMax3(array);
        System.out.println(val);
    }
}
//class Alg4<E> extends Comparable<E> {
class Alg4 <E extends Comparable<E>>{
    public  E findMax(E[] array){
        E max = array[0];
        for (int i = 1;i < array.length;i++){
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}
class Test5{
    public static void main(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] array = {1,2,3,4,5,6,7};
        Integer val = alg2.<Integer>findMax(array);
        System.out.println(val);
    }
}

